Skip to content

Commit

Permalink
Attributes: Attributes, Usage, Target, Multiple, Obsolete
Browse files Browse the repository at this point in the history
  • Loading branch information
theWornOut committed Mar 13, 2018
1 parent a80c929 commit 219fced
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Attributes/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
46 changes: 46 additions & 0 deletions Attributes/Attributes.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9396D2A0-EA67-4C4C-8399-4F61F2D9710D}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Attributes</RootNamespace>
<AssemblyName>Attributes</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
59 changes: 59 additions & 0 deletions Attributes/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
namespace Attributes
{
using System;

internal class Program
{
private static void Main(string[] args)
{
Customer customer = new Customer { Id = 1, LastName = "Alpay", Age = 26 };
CustomerDal customerDal = new CustomerDal();
customerDal.Add(customer);

Console.ReadLine();
}
}

[ToTable("Customers")]
class Customer
{
public int Id { get; set; }

[RequiredProperty]
public string FirstName { get; set; }
[RequiredProperty]
public string LastName { get; set; }
[RequiredProperty]
public int Age { get; set; }
}

class CustomerDal
{
[Obsolete("Don't use Add, instead use AddNew Method")]
public void Add(Customer customer)
{
Console.WriteLine($"{customer.Id} - {customer.FirstName} - {customer.LastName} - {customer.Age} added!");
}

public void AddNew(Customer customer)
{
Console.WriteLine($"{customer.Id} - {customer.FirstName} - {customer.LastName} - {customer.Age} added!");
}
}

[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = true)]
class RequiredPropertyAttribute : Attribute
{

}

[AttributeUsage(AttributeTargets.Class)]
class ToTableAttribute : Attribute
{
private string _tableName;
public ToTableAttribute(string tableName)
{
this._tableName = tableName;
}
}
}
36 changes: 36 additions & 0 deletions Attributes/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Attributes")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Attributes")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("9396d2a0-ea67-4c4c-8399-4f61f2d9710d")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
6 changes: 6 additions & 0 deletions CSharpCourse.sln
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFrameworkDemo", "Enti
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Generics", "Generics\Generics.csproj", "{6B61C52B-ABC8-4FCE-BFD2-581B9B89F30D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Attributes", "Attributes\Attributes.csproj", "{9396D2A0-EA67-4C4C-8399-4F61F2D9710D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -147,6 +149,10 @@ Global
{6B61C52B-ABC8-4FCE-BFD2-581B9B89F30D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6B61C52B-ABC8-4FCE-BFD2-581B9B89F30D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6B61C52B-ABC8-4FCE-BFD2-581B9B89F30D}.Release|Any CPU.Build.0 = Release|Any CPU
{9396D2A0-EA67-4C4C-8399-4F61F2D9710D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9396D2A0-EA67-4C4C-8399-4F61F2D9710D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9396D2A0-EA67-4C4C-8399-4F61F2D9710D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9396D2A0-EA67-4C4C-8399-4F61F2D9710D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 219fced

Please sign in to comment.